package com.netty.config;

import com.netty.server.NettyWebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * @author renyitong
 * @version 1.0.0
 * @createTime 2023年08月16日
 * @Description
 */
@Component
@Slf4j
public class NettyCommandLineRunner implements CommandLineRunner {

    @Autowired
    private NettyWebSocketServer webSocketNettyServer;

    @Autowired
    private NettyConfig nettyConfig;

    @Override
    public void run(String... args) throws Exception {
        new Thread(() -> {
            try {
                log.info("netty服务器正在启动中....");
                webSocketNettyServer.start(nettyConfig.getPort());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
    }
}
